<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchAuditThree">
            <a-icon type="double-right"/>
            审核通过(待平台转账)
          </a-menu-item>
          <a-menu-item key="2" @click="batchAuditFour">
            <a-icon type="double-right"/>
            驳回
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      >

 <span slot="action" slot-scope="text, record">
          <a @click="showDetails(record)" >详情</a>

        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

  </a-card>
</template>

<script>
    import '@/assets/less/TableExpand.less'
    import { postAction, getAction } from '../../api/manage'

    export default {
        name: 'sysCheckBatch',

        data() {
            return {
                description: '批量审核',
                loading: false,
                selectedRowKeys: [],
                selectionRows: [],
                dataSource: [],
                columns: [
                    { title: '#', align: 'center', key: 'rowIndex', width: 80, customRender: (t, r, i) => i + 1 },
                    { title: '批量审核单号', align: 'center', dataIndex: 'auditNo' },
                    { title: '关联账单数量', align: 'center', dataIndex: 'num', },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: 'center',
                        fixed: 'right',
                        width: '100px',
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                url: {
                    list: '/finance/bill/withdrawCash/sysCheck/batchList',
                    batchAuditThree: '/finance/bill/withdrawCash/income/application/batchAuditThree',
                    batchAuditFour: '/finance/bill/withdrawCash/income/application/batchAuditFour'

                },
            }
        },
        created() {
            this.loadData()
        },

        watch: {},
        methods: {
            //批量审核
            batchAuditThree() {
                console.log(this.selectionRows)

                if (this.selectedRowKeys.length <= 0) {
                    this.$message.warning('请选择一条待转账的账单！')
                    return
                } else {

                    var that = this
                    this.$confirm({
                        title: '确认',
                        content: '是否审核通过选中数据?',
                        onOk: function () {
                            that.loading = true
                            postAction(that.url.batchAuditThree, that.selectionRows).then((res) => {
                                if (res.success) {
                                    //重新计算分页问题
                                    that.$message.success('操作成功')
                                    that.loadData()
                                    that.onClearSelected()
                                } else {
                                    that.$message.warning(res.message)
                                }
                            }).finally(() => {
                                that.loading = false
                            })
                        }
                    })
                }
            },
            showDetails(e){
                console.log(e);
                this.$router.push({
                    path:'/finance/sysCheck',
                    query:{
                        'auditNo':e.auditNo
                    }
                })
            },
            batchAuditFour() {
                console.log(this.selectedRowKeys)

                if (this.selectedRowKeys.length <= 0) {
                    this.$message.warning('请选择一条待转账的账单！')
                    return
                } else {

                    var that = this
                    this.$confirm({
                        title: '确认',
                        content: '是否审核通过选中数据?',
                        onOk: function () {
                            that.loading = true
                            postAction(that.url.batchAuditFour, that.selectionRows).then((res) => {
                                if (res.success) {
                                    //重新计算分页问题
                                    that.reCalculatePage(that.selectionRows.length)
                                    that.$message.success('操作成功')
                                    that.loadData()
                                    that.onClearSelected()
                                } else {
                                    that.$message.warning(res.message)
                                }
                            }).finally(() => {
                                that.loading = false
                            })
                        }
                    })
                }
            },
            loadData() {
                this.loading = true,
                    getAction(this.url.list, {}).then(res => {
                        console.log(res)
                        if (res.success) {
                            this.dataSource = res.result
                        } else {
                            this.$message.warning(res.message)
                        }
                    })
                this.loading = false
            },
            handleOk() {
                this.loadData()
                this.$emit('ok')
            },
            onSelectChange(selectedRowKeys, selectionRows) {
                this.selectedRowKeys = selectedRowKeys
                this.selectionRows = selectionRows
            },
            onClearSelected() {
                this.selectedRowKeys = []
                this.selectionRows = []
            },

        }
    }
</script>

<style lang="less" scoped></style>